package com.chx.starter.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.chx.starter.condition.OssCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import com.chx.starter.properties.OssProperties;

@Configuration
@Conditional(OssCondition.class) //验证
@ConditionalOnProperty(prefix = "oss", value = "true", matchIfMissing = true) //是否激活Configuration注解
@EnableConfigurationProperties(OssProperties.class) //激活配置类
public class OssConfiguration {

    @Bean
    public OSS ossClient(OssProperties ossProperties){
        OSS ossClient = new OSSClientBuilder().
                build(ossProperties.getEndpoint(),
                        ossProperties.getAccessKeyId(),
                        ossProperties.getAccessKeySecret());
        return ossClient;
    }
}
